﻿#include "UDeviceConfig.h"
#include <QMessageBox>
#include "CHeader.h"
#include "CSqlOper.h"
UDeviceConfig::UDeviceConfig(CDevBase* pDev,QWidget *parent)
	: QWidget(parent)
{
	this->setProperty("row", 1);
	this->setProperty("col", 1);
	ui.setupUi(this);
	m_pDev = pDev;
	m_pDevData = pDev->m_pDevDataBase;
	m_pDevDataDb = new CDevDataBase();
	getPlcData();
	getDbData();//获取数据库中保存的机器人配置
	initUi();
}

UDeviceConfig::~UDeviceConfig()
{
}

void UDeviceConfig::initUi()
{
	connect(ui.Btn_ReadPlc, &QPushButton::clicked, this, &UDeviceConfig::slot_readFromPlc);
	connect(ui.Btn_WritePlc, &QPushButton::clicked, this, &UDeviceConfig::slot_saveToPlc);
	connect(ui.Btn_ReadDb, &QPushButton::clicked, this, &UDeviceConfig::slot_readFromDb);
	connect(ui.Btn_WriteDb, &QPushButton::clicked, this, &UDeviceConfig::slot_saveToDb);
	connect(ui.Btn_Cancel, &QPushButton::clicked, this, &UDeviceConfig::slot_cancel);
	initUi(m_pDevData);

}

void UDeviceConfig::initUi(CDevDataBase* pDevData)
{
	if (pDevData->lock())
	{
		ui.lineEdit_RobName->setText(pDevData->m_sRobName);
		ui.lineEdit_RobName->setText(pDevData->m_sRobName);
		ui.lineEdit_IP->setText(pDevData->m_sRobotIp);
		ui.lineEdit_Port->setText(pDevData->m_sRobotPort);
		ui.lineEdit_CamerIp->setText(pDevData->m_pDevDataCam->m_sCamerIp);
		ui.lineEdit_CamerPort->setText(QString::number(pDevData->m_pDevDataCam->m_nCamerPort));
		ui.lineEdit_admin->setText(pDevData->m_pDevDataCam->m_sUserName);
		ui.lineEdit_Password->setText(pDevData->m_pDevDataCam->m_sPassWord);
		ui.lineEdit_Path->setText(pDevData->m_pDevDataCam->m_sRecordPath);
		ui.lineEdit_VoiceTime->setText(QString::number(pDevData->m_pDevDataCam->m_nBroadcastTime));

		//plc参数

		//充电参数
		ui.lineEdit_ChargeH->setText(QString::number(pDevData->m_dChargeCutOffThreshold));
		ui.lineEdit_ChargeHV->setText(QString::number(pDevData->m_dChargeCutOffVolTage));
		ui.lineEdit_ChargeHoldH->setText(QString::number(pDevData->m_dHoldingAddPowerThreshold));
		ui.lineEdit_ChargeHoldHV->setText(QString::number(pDevData->m_dHoldingAddPowerVoltage));
		ui.lineEdit_ChargeExecH->setText(QString::number(pDevData->m_dTaskEleQuantityThreshold));
		ui.lineEdit_ChargeExecHV->setText(QString::number(pDevData->m_dTaskEleQuantityVoltage));
		ui.lineEdit_ChargeL->setText(QString::number(pDevData->m_dForceChargeThreshold));
		ui.lineEdit_ChargeLV->setText(QString::number(pDevData->m_dForceChargeVoltage));

		ui.lineEdit_ChargeCycle->setText(QString::number(pDevData->m_dChargeFallLoopCount));
		ui.lineEdit_ComTime->setText(QString::number(pDevData->m_dChargeCommunicationDelay));
		ui.lineEdit_ChargeDistance->setText(QString::number(pDevData->m_dChargeAutoRetornDistance));
		ui.lineEdit_SensorOffset->setText(QString::number(pDevData->m_nProximitySensorOffset));
		ui.lineEdit_SensorOffsetNo2->setText(QString::number(pDevData->m_nNo2LabelOffset));
		ui.lineEdit_OneSpeedCut->setText(QString::number(pDevData->m_dLevelOneSpeedCut));
		ui.lineEdit_TwoSpeedCut->setText(QString::number(pDevData->m_dLevelTwoSpeedCut));
		ui.lineEdit_AutoCharge->setText(QString::number(pDevData->m_nIsOpenAutoCharge));
		//电机参数
		ui.lineEdit_CurrentH->setText(QString::number(pDevData->m_dDriveMotorUpperCurrent));
		ui.lineEdit_CurrentDelay->setText(QString::number(pDevData->m_dDriveMotorCurrentSleep));
		ui.lineEdit_TorqueH->setText(QString::number(pDevData->m_dDriveMotorUpperTorque));
		ui.lineEdit_TorqueDelay->setText(QString::number(pDevData->m_dDriveMotorTorqueSleep));
		ui.lineEdit_TempH->setText(QString::number(pDevData->m_dDriveMotorUpperTemp));
		ui.lineEdit_TempDelay->setText(QString::number(pDevData->m_dDriveMotorTempSleep));
		//升降电机参数
		ui.lineEdit_CurrentH_Z->setText(QString::number(pDevData->m_dLiftMotorUpperCurrent));
		ui.lineEdit_CurrentDelay_Z->setText(QString::number(pDevData->m_dLiftMotorCurrentSleep));
		ui.lineEdit_TorqueH_Z->setText(QString::number(pDevData->m_dLiftMotorUpperTorque));
		ui.lineEdit_TorqueDelay_Z->setText(QString::number(pDevData->m_dLiftMotorTorqueSleep));
		ui.lineEdit_TempH_Z->setText(QString::number(pDevData->m_dLiftMotorUpperTemp));
		ui.lineEdit_TorqueDelay_Z->setText(QString::number(pDevData->m_dLiftMotorTempSleep));
		ui.lineEdit_Speed_Z->setText(QString::number(pDevData->m_dLiftMotorSleepSet));
		//其他综合参数
		ui.lineEdit_StandbyL->setText(QString::number(pDevData->m_dAutoSwitchOpenBatteryThre));
		ui.lineEdit_StandbyLV->setText(QString::number(pDevData->m_dAutoSwitchOpenVolThre));
		ui.lineEdit_AlarmStopTime->setText(QString::number(pDevData->m_nAlarmStopTime));
		ui.lineEdit_ChargePoint->setText(QString::number(pDevData->m_nChargeYTPreset));
		ui.lineEdit_CollectTime->setText(QString::number(pDevData->m_nCollectTime));
		ui.lineEdit_VoiceOffset->setText(QString::number(pDevData->m_nVoiceOffset));
		ui.lineEdit_VoiceAverageTime->setText(QString::number(pDevData->m_nVoiceAverigeTime));
		ui.lineEditFrontObstacleAvoidance->setText(QString::number(pDevData->m_dFrontObstacleAvoidance));
		pDevData->unLock();
	}
}

void UDeviceConfig::getDbData()
{
	selectRobConfig(m_pDevData->m_sDevGuid, m_pDevDataDb);
}

void UDeviceConfig::getPlcData()
{
	//读PLC参数 会将读取到的PLC参数信息保存在CDevDataRob中
	SCtrInfo stCtrInfo;
	stCtrInfo.m_sGuid = m_pDev->m_sDevGuid;
	stCtrInfo.m_bCtrSync = true;
	stCtrInfo.m_bHasCtr = false;
	stCtrInfo.m_nCtrCmd = ECCmdType::enCReadPlcCfg;
	bool bRet = m_pDev->ctrDev(stCtrInfo);
	if (bRet == false)
	{
		/*SExecLog stLog;
		stLog.m_bExecResult = false;
		stLog.m_dLogTime = QDateTime::currentDateTime();
		stLog.m_nAlarmLevel = enSysAlarm;
		stLog.m_sDescriptionl = A2T("从PLC获取机器人配置信息失败");
		stLog.m_sDevName = A2T("PLC");
		ui.labelCurrReadFrom->setText(A2T("PLC连接失败"));
		CLogOper::instance().addMsg(m_sSceneGuid, stLog);*/
		return;
	}

}

bool UDeviceConfig::savePlc(QString& sInfo)
{
	bool bRet = false;
	QMap<QString, double> mapValue = getChangedValue(sInfo);
	if (mapValue.size() == 0)
	{
		bRet = true;
	}
	for (QMap<QString, double>::iterator itor = mapValue.begin(); itor != mapValue.end(); itor++)
	{
		QString sValueName = itor.key();
		double dValue = itor.value();
		//判断哪个值变化了
		if (sValueName == "Speed")
		{
			bRet = writePlc(dValue, enWRobSpeedSet);
		}
		if (sValueName == "FrontObstacleAvoidance")
		{
			bRet = writePlc(dValue, enWFrontObsDis);
		}
		else if (sValueName == "BackObstacleAvoidance")
		{
			bRet = writePlc(dValue, enWRealObsDis);
		}
		else if (sValueName == "ChargeCutoffThreshold")
		{
			bRet = writePlc(dValue, enWChargeLimitThre);
		}
		else if (sValueName == "ChargeCutoffVoltage")
		{
			bRet = writePlc(dValue, enWChargeLimitVol);
		}
		else if (sValueName == "HoldingAddPowerThreshold")
		{
			bRet = writePlc(dValue, enWStanChargeThre);
		}
		else if (sValueName == "HoldingAddPowerVoltage")
		{
			bRet = writePlc(dValue, enWStanChargeVol);
		}
		else if (sValueName == "TaskEleQuantityThreshold")
		{
			bRet = writePlc(dValue, enWTaskExecPowerThre);
		}
		else if (sValueName == "TaskEleQuantityVoltage")
		{
			bRet = writePlc(dValue, enWTaskExecPowerVol);

		}
		else if (sValueName == "ForceChargeThreshold")
		{
			bRet = writePlc(dValue, enWForceChargeThre);
		}
		else if (sValueName == "ForceChargeVoltage")
		{
			bRet = writePlc(dValue, enWForceChargeVol);
		}
		else if (sValueName == "ChargeFailLoopCount")
		{
			bRet = writePlc(dValue, enWChargeFailCyc);
		}
		else if (sValueName == "ChargerCommunicationDelay")
		{
			bRet = writePlc(dValue, enWChargerCommDelay);
		}
		else if (sValueName == "ChargeAutoReturnDistance")
		{
			bRet = writePlc(dValue, enWChargeAutoRetreatDis);
		}
		else if (sValueName == "ProximitySensorOffset")
		{
			bRet = writePlc(dValue, enWProSensorOffset);
		}
		else if (sValueName == "No2LabelOffset")
		{
			bRet = writePlc(dValue, enWTag2Offset);
		}
		else if (sValueName == "LevelOneSpeedCut")
		{
			bRet = writePlc(dValue, enWFirLevelReduc);
		}
		else if (sValueName == "LevelTwoSpeedCut")
		{
			bRet = writePlc(dValue, enWSecLevelReduc);
		}
		else if (sValueName == "IsOpenAutoCharge")
		{
			bRet = writePlc(dValue, enWLowBatteryAutoChargeEn);
		}
		else if (sValueName == "QddjUpperCurrent")
		{
			bRet = writePlc(dValue, enWMotorCurrLimit);
		}
		else if (sValueName == "QddjCurrentSleep")
		{
			bRet = writePlc(dValue, enWMotorCurrDelay);
		}
		else if (sValueName == "QddjUpperTorque")
		{
			bRet = writePlc(dValue, enWMotorTorqueLimit);
		}
		else if (sValueName == "QddjTorqueSleep")
		{
			bRet = writePlc(dValue, enWMotorTorqueDelay);

		}
		else if (sValueName == "QddjUpperTemp")
		{
			bRet = writePlc(dValue, enWMotorTempLimit);
		}
		else if (sValueName == "QddjTempSleep")
		{
			bRet = writePlc(dValue, enWMotorTempDelay);
		}
		else if (sValueName == "SjdjUpperCurrent")
		{
			bRet = writePlc(dValue, enWLiftMotorCurrLimit);
		}
		else if (sValueName == "SjdjCurrentSleep")
		{
			bRet = writePlc(dValue, enWLiftMotorCurrDelay);
		}
		else if (sValueName == "SjdjUpperTorque")
		{
			bRet = writePlc(dValue, enWLiftMotorTorqueLimit);
		}
		else if (sValueName == "SjdjTorqueSleep")
		{
			bRet = writePlc(dValue, enWLiftMotoTorqueDelay);
		}
		else if (sValueName == "SjdjUpperTemp")
		{
			bRet = writePlc(dValue, enWLiftMotoTemp);
		}
		else if (sValueName == "SjdjTempSleep")
		{
			bRet = writePlc(dValue, enWLiftMotoTempDelay);
		}
		else if (sValueName == "SjdjSpeed")
		{
			bRet = writePlc(dValue, enWLiftSpeed);
		}
		else if (sValueName == "AutoSwitchOpenBatteryThre")
		{
			bRet = writePlc(dValue, enWAutoSwitchOpenBatteryThre);
		}
		else if (sValueName == "AutoSwitchOpenVolThre")
		{
			bRet = writePlc(dValue, enWAutoSwitchOpenVolThre);
		}
		else if (sValueName == "IsAutoFlush")
		{
			bRet = writePlc(dValue, enWIsAutoFlush);
		}
		else if (sValueName == "FlushPlaceOffset")
		{
			bRet = writePlc(dValue, enWFlushPlaceOffset);
		}
		else if (sValueName == "FlushRFID1")
		{
			bRet = writePlc(dValue, enWFlushRFID1);
		}
		else if (sValueName == "FlushRFID2")
		{
			bRet = writePlc(dValue, enWFlushRFID2);
		}
		else if (sValueName == "AlarmStopTime")
		{
			bRet = writePlc(dValue, enWAlarmStopTime);
		}
		else if (sValueName == "ChargeYTPreset")
		{
			bRet = writePlc(dValue, enWChargeYTPreset);
		}
		else if (sValueName == "CollectTime")
		{
			bRet = writePlc(dValue, enWCollectTime);
		}
	}
	return bRet;
}
bool UDeviceConfig::writePlc(int dValue,EWAddrNameRob enWAddr)
{

	SCtrInfo stCtrInfo;
	stCtrInfo.m_sGuid = m_pDev->m_sDevGuid;
	stCtrInfo.m_bCtrSync = true;
	stCtrInfo.m_bHasCtr = false;
	stCtrInfo.m_nCtrCmd = ECCmdType::enCWritePlcCfg;
	stCtrInfo.m_nWriteAddr = m_pDevData->m_mapAddrDataW[enWAddr].m_sAddrData.toInt();
	stCtrInfo.m_nAddrLen = m_pDevData->m_mapAddrDataW[enWAddr].m_nAddrLength;
	stCtrInfo.m_nValue = (int)dValue;
	bool bRet = m_pDev->ctrDev(stCtrInfo);
	return bRet;
}
QMap<QString, double> UDeviceConfig::getChangedValue(QString& sInfo)
{
	QMap<QString, double> mapValue;
	mapValue.clear();
	//if ((ui.lineEditSpeed->text().toDouble()) != m_pDevDataPlc->m_dRobRunSpeed)
	//{
	//	mapValue.insert("Speed", (ui.lineEditSpeed->text().toDouble()));
	//	sInfo += A2T("默认巡检速度由%1变为%2/").arg(m_pDevDataPlc->m_dRobRunSpeed).arg(ui.lineEditSpeed->text().toDouble());
	//}
	if ((ui.lineEditFrontObstacleAvoidance->text().toDouble()) != m_pDevData->m_dFrontObstacleAvoidance)
	{
		mapValue.insert("FrontObstacleAvoidance", (ui.lineEditFrontObstacleAvoidance->text().toDouble()));
		sInfo += A2T("避障开关由%1变为%2/").arg(m_pDevData->m_dFrontObstacleAvoidance).arg(ui.lineEditFrontObstacleAvoidance->text().toDouble());
	}
	//if ((ui.lineEditBackObstacleAvoidance->text().toDouble()) != m_pDevDataPlc->m_dBackObstanceAvidance)
	//{
	//	mapValue.insert("BackObstacleAvoidance", (ui.lineEditBackObstacleAvoidance->text().toDouble()));
	//	sInfo += A2T("跨皮带保护由%1变为%2/").arg(m_pDevDataPlc->m_dBackObstanceAvidance).arg(ui.lineEditBackObstacleAvoidance->text().toDouble());
	//}
	if ((ui.lineEdit_ChargeH->text().toDouble()) != m_pDevData->m_dChargeCutOffThreshold)
	{
		mapValue.insert("ChargeCutoffThreshold", (ui.lineEdit_ChargeH->text().toDouble() * 100));
		sInfo += A2T("充电截止阈值由%1变为%2/").arg(m_pDevData->m_dChargeCutOffThreshold).arg(ui.lineEdit_ChargeH->text().toDouble());
	}
	if ((ui.lineEdit_ChargeHV->text().toDouble()) != m_pDevData->m_dChargeCutOffVolTage)
	{
		mapValue.insert("ChargeCutoffVoltage", (ui.lineEdit_ChargeHV->text().toDouble() * 100));
		sInfo += A2T("充电截止电压由%1变为%2/").arg(m_pDevData->m_dChargeCutOffVolTage).arg(ui.lineEdit_ChargeHV->text().toDouble());
	}
	if ((ui.lineEdit_ChargeHoldH->text().toDouble()) != m_pDevData->m_dHoldingAddPowerThreshold)
	{
		mapValue.insert("HoldingAddPowerThreshold", (ui.lineEdit_ChargeHoldH->text().toDouble() * 100));
		sInfo += A2T("待机补电阈值由%1变为%2/").arg(m_pDevData->m_dHoldingAddPowerThreshold).arg(ui.lineEdit_ChargeHoldH->text().toDouble());
	}
	if ((ui.lineEdit_ChargeHoldHV->text().toDouble()) != m_pDevData->m_dHoldingAddPowerVoltage)
	{
		mapValue.insert("HoldingAddPowerVoltage", (ui.lineEdit_ChargeHoldHV->text().toDouble() * 100));
		sInfo += A2T("待机补电电压由%1变为%2").arg(m_pDevData->m_dHoldingAddPowerVoltage).arg(ui.lineEdit_ChargeHoldHV->text().toDouble());
	}
	if ((ui.lineEdit_ChargeExecH->text().toDouble()) != m_pDevData->m_dTaskEleQuantityThreshold)
	{
		mapValue.insert("TaskEleQuantityThreshold", (ui.lineEdit_ChargeExecH->text().toDouble() * 100));
		sInfo += A2T("执行任务电量阈值由%1变为%2/").arg(m_pDevData->m_dTaskEleQuantityThreshold).arg(ui.lineEdit_ChargeExecH->text().toDouble());
	}
	if ((ui.lineEdit_ChargeExecHV->text().toDouble()) != m_pDevData->m_dTaskEleQuantityVoltage)
	{
		mapValue.insert("TaskEleQuantityVoltage", (ui.lineEdit_ChargeExecHV->text().toDouble() * 100));
		sInfo += A2T("执行任务电量电压由%1变为%2/").arg(m_pDevData->m_dTaskEleQuantityVoltage).arg(ui.lineEdit_ChargeExecHV->text().toDouble());
	}
	if ((ui.lineEdit_ChargeL->text().toDouble()) != m_pDevData->m_dForceChargeThreshold)
	{
		mapValue.insert("ForceChargeThreshold", (ui.lineEdit_ChargeL->text().toDouble() * 100));
		sInfo += A2T("强制充电阈值由%1变为%2/").arg(m_pDevData->m_dForceChargeThreshold).arg(ui.lineEdit_ChargeL->text().toDouble());
	}
	if ((ui.lineEdit_ChargeLV->text().toDouble()) != m_pDevData->m_dForceChargeVoltage)
	{
		mapValue.insert("ForceChargeVoltage", (ui.lineEdit_ChargeLV->text().toDouble() * 100));
		sInfo += A2T("强制充电电压由%1变为%2/").arg(m_pDevData->m_dForceChargeVoltage).arg(ui.lineEdit_ChargeLV->text().toDouble());
	}
	if ((ui.lineEdit_ChargeCycle->text().toDouble()) != m_pDevData->m_dChargeFallLoopCount)
	{
		mapValue.insert("ChargeFailLoopCount", (ui.lineEdit_ChargeCycle->text().toDouble()));
		sInfo += A2T("充电失败循环次数由%1变为%2/").arg(m_pDevData->m_dChargeFallLoopCount).arg(ui.lineEdit_ChargeCycle->text().toDouble());
	}
	if ((ui.lineEdit_ComTime->text().toDouble()) != m_pDevData->m_dChargeCommunicationDelay)
	{
		mapValue.insert("ChargerCommunicationDelay", (ui.lineEdit_ComTime->text().toDouble()));
		sInfo += A2T("充电器通讯延时由%1变为%2").arg(m_pDevData->m_dChargeCommunicationDelay).arg(ui.lineEdit_ComTime->text().toDouble());
	}
	if ((ui.lineEdit_ChargeDistance->text().toDouble()) != m_pDevData->m_dChargeAutoRetornDistance)
	{
		mapValue.insert("ChargeAutoReturnDistance", (ui.lineEdit_ChargeDistance->text().toDouble() * 100));
		sInfo += A2T("充电自动退回距离由%1变为%2/").arg(m_pDevData->m_dChargeAutoRetornDistance).arg(ui.lineEdit_ChargeDistance->text().toDouble());
	}
	if ((ui.lineEdit_SensorOffset->text().toDouble()) != m_pDevData->m_nProximitySensorOffset)
	{
		mapValue.insert("ProximitySensorOffset", (ui.lineEdit_SensorOffset->text().toDouble()));
		sInfo += A2T("接近开关至充电位补偿由%1变为%2/").arg(m_pDevData->m_nProximitySensorOffset).arg(ui.lineEdit_SensorOffset->text().toDouble());
	}
	if ((ui.lineEdit_SensorOffsetNo2->text().toDouble()) != m_pDevData->m_nNo2LabelOffset)
	{
		mapValue.insert("No2LabelOffset", (ui.lineEdit_SensorOffsetNo2->text().toDouble()));
		sInfo += A2T("2#标签至充电位补偿由%1变为%2/").arg(m_pDevData->m_nNo2LabelOffset).arg(ui.lineEdit_SensorOffsetNo2->text().toDouble());
	}
	if ((ui.lineEdit_OneSpeedCut->text().toDouble()) != m_pDevData->m_dLevelOneSpeedCut)
	{
		mapValue.insert("LevelOneSpeedCut", (ui.lineEdit_OneSpeedCut->text().toDouble() * 100));
		sInfo += A2T("一级减速由%1变为%2/").arg(m_pDevData->m_dLevelOneSpeedCut).arg(ui.lineEdit_OneSpeedCut->text().toDouble());
	}
	if ((ui.lineEdit_TwoSpeedCut->text().toDouble()) != m_pDevData->m_dLevelTwoSpeedCut)
	{
		mapValue.insert("LevelTwoSpeedCut", (ui.lineEdit_TwoSpeedCut->text().toDouble() * 100));
		sInfo += A2T("二级减速由%1变为%2/").arg(m_pDevData->m_dLevelTwoSpeedCut).arg(ui.lineEdit_TwoSpeedCut->text().toDouble());
	}
	if ((ui.lineEdit_AutoCharge->text().toDouble()) != m_pDevData->m_nIsOpenAutoCharge)
	{
		mapValue.insert("IsOpenAutoCharge", (ui.lineEdit_AutoCharge->text().toDouble()));
		sInfo += A2T("是否开启低电量自动充电由%1变为%2/").arg(m_pDevData->m_nIsOpenAutoCharge).arg(ui.lineEdit_AutoCharge->text().toDouble());
	}
	if ((ui.lineEdit_CurrentH->text().toDouble()) != m_pDevData->m_dDriveMotorUpperCurrent)
	{
		mapValue.insert("QddjUpperCurrent", (ui.lineEdit_CurrentH->text().toDouble() * 100));
		sInfo += A2T("驱动电机电流上限由%1变为%2/").arg(m_pDevData->m_dDriveMotorUpperCurrent).arg(ui.lineEdit_CurrentH->text().toDouble());
	}
	if ((ui.lineEdit_CurrentDelay->text().toDouble()) != m_pDevData->m_dDriveMotorCurrentSleep)
	{
		mapValue.insert("QddjCurrentSleep", (ui.lineEdit_CurrentDelay->text().toDouble()));
		sInfo += A2T("驱动电机电流延时由%1变为%2/").arg(m_pDevData->m_dDriveMotorCurrentSleep).arg(ui.lineEdit_CurrentDelay->text().toDouble());
	}
	if ((ui.lineEdit_TorqueH->text().toDouble()) != m_pDevData->m_dDriveMotorUpperTorque)
	{
		mapValue.insert("QddjUpperTorque", (ui.lineEdit_TorqueH->text().toDouble() * 100));
		sInfo += A2T("驱动电机扭矩上限由%1变为%2/").arg(m_pDevData->m_dDriveMotorUpperTorque).arg(ui.lineEdit_TorqueH->text().toDouble());
	}
	if ((ui.lineEdit_TorqueDelay->text().toDouble()) != m_pDevData->m_dDriveMotorTorqueSleep)
	{
		mapValue.insert("QddjTorqueSleep", (ui.lineEdit_TorqueDelay->text().toDouble()));
		sInfo += A2T("驱动电机扭矩延时由%1变为%2/").arg(m_pDevData->m_dDriveMotorTorqueSleep).arg(ui.lineEdit_TorqueDelay->text().toDouble());
	}
	if ((ui.lineEdit_TempH->text().toDouble()) != m_pDevData->m_dDriveMotorUpperTemp)
	{
		mapValue.insert("QddjUpperTemp", (ui.lineEdit_TempH->text().toDouble()));
		sInfo += A2T("驱动电机温度上限由%1变为%2/").arg(m_pDevData->m_dDriveMotorUpperTemp).arg(ui.lineEdit_TempH->text().toDouble());
	}
	if ((ui.lineEdit_TempDelay->text().toDouble()) != m_pDevData->m_dDriveMotorTempSleep)
	{
		mapValue.insert("QddjTempSleep", (ui.lineEdit_TempDelay->text().toDouble()));
		sInfo += A2T("驱动电机温度延时由%1变为%2/").arg(m_pDevData->m_dDriveMotorTempSleep).arg(ui.lineEdit_TempDelay->text().toDouble());
	}
	if ((ui.lineEdit_CurrentH_Z->text().toDouble()) != m_pDevData->m_dLiftMotorUpperCurrent)
	{
		mapValue.insert("SjdjUpperCurrent", (ui.lineEdit_CurrentH_Z->text().toDouble() * 100));
		sInfo += A2T("升降电机电流上限由%1变为%2/").arg(m_pDevData->m_dLiftMotorUpperCurrent).arg(ui.lineEdit_CurrentH_Z->text().toDouble());
	}
	if ((ui.lineEdit_CurrentDelay_Z->text().toDouble()) != m_pDevData->m_dLiftMotorCurrentSleep)
	{
		mapValue.insert("SjdjCurrentSleep", (ui.lineEdit_CurrentDelay_Z->text().toDouble()));
		sInfo += A2T("升降电机电流延时由%1变为%2/").arg(m_pDevData->m_dLiftMotorCurrentSleep).arg(ui.lineEdit_CurrentDelay_Z->text().toDouble());
	}
	if ((ui.lineEdit_TorqueH_Z->text().toDouble()) != m_pDevData->m_dLiftMotorUpperTorque)
	{
		mapValue.insert("SjdjUpperTorque", (ui.lineEdit_TorqueH_Z->text().toDouble() * 100));
		sInfo += A2T("升降电机扭矩上限由%1变为%2/").arg(m_pDevData->m_dRobRunSpeed).arg(ui.lineEdit_TorqueH_Z->text().toDouble());
	}
	if ((ui.lineEdit_TorqueDelay_->text().toDouble()) != m_pDevData->m_dLiftMotorTorqueSleep)
	{
		mapValue.insert("SjdjTorqueSleep", (ui.lineEdit_TorqueDelay_->text().toDouble()));
		sInfo += A2T("升降电机扭矩延时由%1变为%2").arg(m_pDevData->m_dLiftMotorTorqueSleep).arg(ui.lineEdit_TorqueDelay_->text().toDouble());
	}
	if ((ui.lineEdit_TempH_Z->text().toDouble()) != m_pDevData->m_dLiftMotorUpperTemp)
	{
		mapValue.insert("SjdjUpperTemp", (ui.lineEdit_TempH_Z->text().toDouble()));
		sInfo += A2T("升降电机温度上限由%1变为%2/").arg(m_pDevData->m_dLiftMotorUpperTemp).arg(ui.lineEdit_TempH_Z->text().toDouble());
	}
	if ((ui.lineEdit_TorqueDelay_Z->text().toDouble()) != m_pDevData->m_dLiftMotorTempSleep)
	{
		mapValue.insert("SjdjTempSleep", (ui.lineEdit_TorqueDelay_Z->text().toDouble()));
		sInfo += A2T("升降电机温度延时由%1变为%2/").arg(m_pDevData->m_dLiftMotorTempSleep).arg(ui.lineEdit_TorqueDelay_Z->text().toDouble());
	}
	if ((ui.lineEdit_Speed_Z->text().toDouble()) != m_pDevData->m_dLiftMotorSleepSet)
	{
		mapValue.insert("SjdjSpeed", (ui.lineEdit_Speed_Z->text().toDouble()));
		sInfo += A2T("升降电机速度由%1变为%2/").arg(m_pDevData->m_dLiftMotorSleepSet).arg(ui.lineEdit_Speed_Z->text().toDouble());
	}
	if ((ui.lineEdit_StandbyL->text().toDouble()) != m_pDevData->m_dAutoSwitchOpenBatteryThre)
	{
		mapValue.insert("AutoSwitchOpenBatteryThre", (ui.lineEdit_StandbyL->text().toDouble() * 100));
		sInfo += A2T("自动分闸电量阈值由%1变为%2/").arg(m_pDevData->m_dAutoSwitchOpenBatteryThre).arg(ui.lineEdit_StandbyL->text().toDouble());
	}
	if ((ui.lineEdit_StandbyLV->text().toDouble()) != m_pDevData->m_dAutoSwitchOpenVolThre)
	{
		mapValue.insert("AutoSwitchOpenVolThre", (ui.lineEdit_StandbyLV->text().toDouble() * 100));
		sInfo += A2T("自动分闸电压阈值由%1变为%2/").arg(m_pDevData->m_dAutoSwitchOpenVolThre).arg(ui.lineEdit_StandbyLV->text().toDouble());
	}
	//if ((ui.lineEditFlushRFID1->text().toDouble()) != m_pDevData->m_nFlushRFID1)
	//{
	//	mapValue.insert("FlushRFID1", (ui.lineEditFlushRFID1->text().toDouble()));
	//	sInfo += A2T("冲洗位置前RFID号由%1变为%2/").arg(m_pDevData->m_nFlushRFID1).arg(ui.lineEditFlushRFID1->text().toDouble());
	//}
	//if ((ui.lineEditFlushRFID2->text().toDouble()) != m_pDevData->m_nFlushRFID2)
	//{
	//	mapValue.insert("FlushRFID2", (ui.lineEditFlushRFID2->text().toDouble()));
	//	sInfo += A2T("冲洗位置后RFID号由%1变为%2/").arg(m_pDevData->m_nFlushRFID2).arg(ui.lineEditFlushRFID2->text().toDouble());
	//}
	//if ((ui.lineEditFlushPlaceOffset->text().toDouble()) != m_pDevData->m_dFlushPlaceOffset)
	//{
	//	mapValue.insert("FlushPlaceOffset", (ui.lineEditFlushPlaceOffset->text().toDouble()));
	//	sInfo += A2T("冲洗位置补偿由%1变为%2/").arg(m_pDevData->m_dFlushPlaceOffset).arg(ui.lineEditFlushPlaceOffset->text().toDouble());
	//}
	if ((ui.lineEdit_AlarmStopTime->text().toDouble()) != m_pDevData->m_nAlarmStopTime)
	{
		mapValue.insert("AlarmStopTime", (ui.lineEdit_AlarmStopTime->text().toDouble()));
		sInfo += A2T("报警停留时间由%1变为%2/").arg(m_pDevData->m_nAlarmStopTime).arg(ui.lineEdit_AlarmStopTime->text().toDouble());
	}
	if ((ui.lineEdit_ChargePoint->text().toDouble()) != m_pDevData->m_nChargeYTPreset)
	{
		mapValue.insert("ChargeYTPreset", (ui.lineEdit_ChargePoint->text().toDouble()));
		sInfo += A2T("云台充电预置点由%1变为%2/").arg(m_pDevData->m_nChargeYTPreset).arg(ui.lineEdit_ChargePoint->text().toDouble());
	}
	if ((ui.lineEdit_CollectTime->text().toDouble()) != m_pDevData->m_nCollectTime)
	{
		mapValue.insert("CollectTime", (ui.lineEdit_CollectTime->text().toDouble()));
		sInfo += A2T("云台巡检项采集时间由%1变为%2/").arg(m_pDevData->m_nCollectTime).arg(ui.lineEdit_CollectTime->text().toDouble());
	}
	return mapValue;
}

void UDeviceConfig::slot_saveToPlc()
{
	int nRet = messageBox(3, A2T("是否确定保存到PLC"));
	if (nRet == QMessageBox::No)
	{
		return;
	}

	QString sInfo = "";
	//写PLC 变化了的才写
	bool bSavePlc = savePlc(sInfo);//保存值到Plc
	if (bSavePlc == true)
	{
		messageBox(0, A2T("往PLC写机器人配置信息成功"));
	}
	else
	{
		messageBox(2, A2T("往PLC写机器人配置信息失败"));
	}
}

void UDeviceConfig::slot_readFromPlc()
{
	getPlcData();
	initUi(m_pDevData);
}

void UDeviceConfig::slot_saveToDb()
{
	int nRet = messageBox(3, A2T("是否确定保存到数据库"));
	if (nRet == QMessageBox::No || QMessageBox::Close == nRet)
	{
		return;
	}
	m_pDevDataDb->m_sDevGuid = m_pDev->m_sDevGuid;
	m_pDevDataDb->m_sRobName=ui.lineEdit_RobName->text();
	m_pDevDataDb->m_sRobotIp=ui.lineEdit_IP->text();
	m_pDevDataDb->m_sRobotPort = ui.lineEdit_Port->text();
	//m_pDevDataDb->m_dRobRunSpeed = ui.lineEditSpeed->text().toDouble();
	//m_pDevDataDb->m_dOneClickBaceLocation = ui.lineEditOneClickBackLocation->text().toDouble();

	m_pDevDataDb->m_dFrontObstacleAvoidance = ui.lineEditFrontObstacleAvoidance->text().toDouble();
	//m_pDevDataDb->m_dBackObstanceAvidance = ui.lineEditBackObstacleAvoidance->text().toDouble();

	m_pDevDataDb->m_dChargeCutOffThreshold = ui.lineEdit_ChargeH->text().toDouble();
	m_pDevDataDb->m_dChargeCutOffVolTage = ui.lineEdit_ChargeHV->text().toDouble();
	m_pDevDataDb->m_dHoldingAddPowerThreshold = ui.lineEdit_ChargeHoldH->text().toDouble();
	m_pDevDataDb->m_dHoldingAddPowerVoltage = ui.lineEdit_ChargeHoldHV->text().toDouble();
	m_pDevDataDb->m_dTaskEleQuantityThreshold = ui.lineEdit_ChargeExecH->text().toDouble();
	m_pDevDataDb->m_dTaskEleQuantityVoltage = ui.lineEdit_ChargeExecHV->text().toDouble();
	m_pDevDataDb->m_dForceChargeThreshold = ui.lineEdit_ChargeL->text().toDouble();
	m_pDevDataDb->m_dForceChargeVoltage = ui.lineEdit_ChargeLV->text().toDouble();
	m_pDevDataDb->m_dChargeFallLoopCount = ui.lineEdit_ChargeCycle->text().toDouble();
	m_pDevDataDb->m_dChargeCommunicationDelay = ui.lineEdit_ComTime->text().toDouble();
	m_pDevDataDb->m_dChargeAutoRetornDistance = ui.lineEdit_ChargeDistance->text().toDouble();
	m_pDevDataDb->m_nProximitySensorOffset = ui.lineEdit_SensorOffset->text().toDouble();
	m_pDevDataDb->m_nNo2LabelOffset = ui.lineEdit_SensorOffsetNo2->text().toDouble();
	m_pDevDataDb->m_dLevelOneSpeedCut = ui.lineEdit_OneSpeedCut->text().toDouble();
	m_pDevDataDb->m_dLevelTwoSpeedCut = ui.lineEdit_TwoSpeedCut->text().toDouble();
	m_pDevDataDb->m_nIsOpenAutoCharge = ui.lineEdit_AutoCharge->text().toDouble();

	m_pDevDataDb->m_dDriveMotorUpperCurrent = ui.lineEdit_CurrentH->text().toDouble();
	m_pDevDataDb->m_dDriveMotorCurrentSleep = ui.lineEdit_CurrentDelay->text().toDouble();
	m_pDevDataDb->m_dDriveMotorUpperTorque = ui.lineEdit_TorqueH->text().toDouble();
	m_pDevDataDb->m_dDriveMotorTorqueSleep = ui.lineEdit_TorqueDelay->text().toDouble();
	m_pDevDataDb->m_dDriveMotorUpperTemp = ui.lineEdit_TempH->text().toDouble();
	m_pDevDataDb->m_dDriveMotorTempSleep = ui.lineEdit_TempDelay->text().toDouble();

	m_pDevDataDb->m_dLiftMotorUpperCurrent = ui.lineEdit_CurrentH_Z->text().toDouble();
	m_pDevDataDb->m_dLiftMotorCurrentSleep = ui.lineEdit_CurrentDelay_Z->text().toDouble();
	m_pDevDataDb->m_dLiftMotorUpperTorque = ui.lineEdit_TorqueH_Z->text().toDouble();
	m_pDevDataDb->m_dLiftMotorTorqueSleep = ui.lineEdit_TorqueDelay_->text().toDouble();
	m_pDevDataDb->m_dLiftMotorUpperTemp = ui.lineEdit_TempH_Z->text().toDouble();
	m_pDevDataDb->m_dLiftMotorTempSleep = ui.lineEdit_TorqueDelay_Z->text().toDouble();
	m_pDevDataDb->m_dLiftMotorSleepSet = ui.lineEdit_Speed_Z->text().toDouble();

	/*m_pDevDataDb->m_nFlushRFID1 = ui.lineEditFlushRFID1->text().toInt();
	m_pDevDataDb->m_nFlushRFID2 = ui.lineEditFlushRFID2->text().toInt();*/
	m_pDevDataDb->m_dAutoSwitchOpenBatteryThre = ui.lineEdit_StandbyL->text().toDouble();
	m_pDevDataDb->m_dAutoSwitchOpenVolThre = ui.lineEdit_StandbyLV->text().toDouble();
	//m_pDevDataDb->m_dFlushPlaceOffset = ui.lineEditFlushPlaceOffset->text().toDouble();
	m_pDevDataDb->m_nAlarmStopTime = ui.lineEdit_AlarmStopTime->text().toInt();
	m_pDevDataDb->m_nChargeYTPreset = ui.lineEdit_ChargePoint->text().toInt();
	m_pDevDataDb->m_nCollectTime = ui.lineEdit_CollectTime->text().toInt();
	m_pDevDataDb->m_nVoiceOffset = ui.lineEdit_VoiceOffset->text().toInt();
	m_pDevDataDb->m_nVoiceAverigeTime = ui.lineEdit_VoiceAverageTime->text().toInt();
	m_pDevDataDb->m_nAutoChargeThreshold = ui.lineEdit_StandbyL->text().toDouble();
	bool bHostRet = false;
	QString sErrMsg = "";
	bHostRet = updateRobHostDevice(m_pDevDataDb, sErrMsg);
	if (bHostRet == false)
	{
		messageBox(2, A2T("更新数据库的机器人主机数据失败"));
		return;
	}
	CDevDataCam* pDevDataCam = m_pDevDataDb->m_pDevDataCam;
	pDevDataCam->m_sRobHostGuid = m_pDev->m_sDevGuid;
	pDevDataCam->m_sCamerIp = ui.lineEdit_CamerIp->text();
	pDevDataCam->m_nCamerPort = ui.lineEdit_CamerPort->text().toInt();
	pDevDataCam->m_sUserName = ui.lineEdit_admin->text();
	pDevDataCam->m_sPassWord = ui.lineEdit_Password->text();
	pDevDataCam->m_sRecordPath = ui.lineEdit_Path->text();
	pDevDataCam->m_nBroadcastTime = ui.lineEdit_VoiceTime->text().toInt();
	bool bRetPan = updatePanTiltConfig(pDevDataCam, sErrMsg);
	if (bRetPan == false)
	{
		messageBox(2, A2T("更新数据库的云台数据失败"));
		return;
	}
	messageBox(0, A2T("保存到数据库成功"));
}

void UDeviceConfig::slot_readFromDb()
{
	getPlcData();
	initUi(m_pDevDataDb);
}

void UDeviceConfig::slot_cancel()
{
	close();
}
